Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
The uniqs npm package is a simple utility that allows you to filter out duplicate values from an array. It is particularly useful when you need to ensure that a list contains only unique items.
Removing duplicates from an array
This feature allows you to pass an array to the uniqs function, and it returns a new array with all the duplicate values removed, leaving only unique items.
[...new Set([1, 2, 2, 3, 4, 4, 5])] // returns [1, 2, 3, 4, 5]
lodash.uniq is a method from the popular Lodash library that produces a duplicate-free version of an array. It is similar to uniqs but comes as part of a larger utility library, which might be more suitable for projects that require a wide range of utility functions.
Underscore.js is a utility library that contains a uniq function, which is similar to uniqs. It offers a broader set of utility functions for manipulating and working with data. Unlike uniqs, which is focused solely on array deduplication, Underscore provides a more extensive toolkit for various operations.
array-unique is another npm package that removes duplicate values from an array. It is similar to uniqs in functionality but may have different performance characteristics or implementation details.
Example:
var uniqs = require('uniqs');
var foo = { foo: 23 };
var list = [3, 2, 2, 1, foo, foo];
uniqs(list);
// => [3, 2, 1, { foo: 23 }]
You can pass multiple lists to create a union:
uniqs([2, 1, 1], [2, 3, 3, 4], [4, 3, 2]);
// => [2, 1, 3, 4]
Passing individual items works too:
uniqs(3, 2, 2, [1, 1, 2]);
// => [3, 2, 1]
This package has been written to accompany utilities like flatten as alternative to full-blown libraries like underscore or lodash.
The implementation is optimized for simplicity rather than performance and looks like this:
module.exports = function uniqs() {
var list = Array.prototype.concat.apply([], arguments);
return list.filter(function(item, i) {
return i == list.indexOf(item);
});
};
MIT
FAQs
Tiny utility to create unions and de-duplicated lists
The npm package uniqs receives a total of 2,185,732 weekly downloads. As such, uniqs popularity was classified as popular.
We found that uniqs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.